package values.skill
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	import flash.utils.Dictionary;
	
	import values.avatar.IAvatarValue;
	
	public class ImmediateEffectValue extends EventDispatcher implements IImmediateEffectValue
	{
		public function ImmediateEffectValue()
		{
			super();
		}
		
		private var _owner:IAvatarValue;
		
		private var _skillValue:SkillValue; 
		
		public function init(owner:IAvatarValue, skillValue:SkillValue):void
		{
			changeDic = new Dictionary(true);
			
			_owner = owner;
			
			_skillValue = skillValue;
			
			var templateV:ImmediateEffectTemplateValue = skillValue.template.immediate;
			
			for each(var proV:ImmediateProTemplateValue in templateV.proDic)
			{
				if(_owner[proV.proName] != null)
				{
					var num:Number = 0;
					if(proV.baseNum.indexOf("{") == -1)
					{
						num = Number(proV.baseNum.indexOf("{"));
					}
					else
					{
						num = skillValue.getLevelValueByTag(proV.baseNum);
					}
					
					changeDic[proV.proName] = _owner[proV.proName];
					_owner[proV.proName] -= SkillNumTypeKey.getResult(proV.numType , _owner[proV.proName] , num);
					
				}
			}
		}
		
		private var changeDic:Dictionary;
		
		public function recover():void
		{
			for(var value:* in changeDic)
			{
				_owner[value] = changeDic[value];
			}
			
			changeDic = null;
		}
		
		public function dispose():void
		{
			changeDic = null;
			_owner = null;
			_skillValue = null;
		}
	}
}